<template>
    <div class="basis-info">
        <div class="basis_content">
            <Form ref="basicTypeForm" :model="basicTypeForm"  v-bind:disabled="true"  :label-width="180">
                <!--基本信息   -->
                <Card>
                <div class="common_br">
                    <h2 class="common_channel_title" >基本信息</h2>
                    <div class="common_content">
                        <Row>
                            <Col span="8">
                                <FormItem label="合作商代码"  prop="channelCode" >
                                    <Input v-model="basicTypeForm.channelCode"  readonly="readonly"  class="w200" placeholder="系统自动生成"/>
                                </FormItem>
                            </Col>

                            <Col span="8">
                                <FormItem label="合作商名称" prop="channelFullName">
                                    <Input v-model.trim="basicTypeForm.channelFullName"   class="w200"  placeholder="请输入"/>
                                </FormItem>
                            </Col>

                            <Col span="8">
                                <FormItem label="上线日期" prop="onlineDate" >
                                    <Date-picker type="date" v-model="basicTypeForm.onlineDate" class="w200"  placeholder="选择日期" ></Date-picker>
                                </FormItem>
                            </Col>
                        </Row>

                        <Row>
                            <Col span="8">
                                <FormItem label="统一社会信用代码" prop="socUniCrtCode">
                                    <Input v-model.trim="basicTypeForm.socUniCrtCode" class="w200"  placeholder="请输入"/>
                                </FormItem>
                            </Col>
                            <Col span="8">
                                <FormItem label="法人" prop="legalPerson">
                                    <Input v-model.trim="basicTypeForm.legalPerson"   class="w200"  placeholder="请输入"/>
                                </FormItem>
                            </Col>
                            <Col span="8">
                                <FormItem label="法人身份证号" prop="legalPersonIdCard">
                                    <Input v-model.trim="basicTypeForm.legalPersonIdCard"    class="w200"  placeholder="请输入"/>
                                </FormItem>
                            </Col>
                        </Row>

                        <Row>
                            <Col span="8">
                                <FormItem label="法人电话" prop="legalPersonTel">
                                    <Input v-model.trim="basicTypeForm.legalPersonTel"    class="w200"  placeholder="请输入"/>
                                </FormItem>
                            </Col>

                            <Col span="8">
                                <FormItem label="实际控制人" prop="actualController">
                                    <Input v-model.trim="basicTypeForm.actualController"   class="w200"  placeholder="请输入"/>
                                </FormItem>
                            </Col>

                            <Col span="8">
                                <FormItem label="实际控制人电话" prop="actualControllerTel">
                                    <Input v-model.trim="basicTypeForm.actualControllerTel"   class="w200"  placeholder="请输入"/>
                                </FormItem>
                            </Col>

                        </Row>

                        <Row>
                            <Col span="8">
                                <FormItem label="实际控制人身份证号" prop="actualControllerIdCard">
                                    <Input v-model.trim="basicTypeForm.actualControllerIdCard"   class="w200"  placeholder="请输入"/>
                                </FormItem>
                            </Col>

                            <Col span="8">
                                <FormItem label="管理员姓名" prop="channelAdmin">
                                    <Input v-model.trim="basicTypeForm.channelAdmin"    class="w200"  placeholder="请输入"/>
                                </FormItem>
                            </Col>

                            <Col span="8">
                                <FormItem label="管理员电话" prop="channelAdminTel">
                                    <Input v-model.trim="basicTypeForm.channelAdminTel"   class="w200"  placeholder="请输入"/>
                                </FormItem>
                            </Col>
                        </Row>

                        <Row>
                            <Col span="8">
                                <FormItem label="管理员邮箱" prop="channelAdminMail">
                                    <Input v-model.trim="basicTypeForm.channelAdminMail"   class="w200"  placeholder="请输入"/>
                                </FormItem>
                            </Col>

                            <Col span="8">
                                <FormItem label="管理员证件号码" prop="channelAdminIdCard">
                                    <Input v-model.trim="basicTypeForm.channelAdminIdCard"   class="w200"  placeholder="请输入"/>
                                </FormItem>
                            </Col>
                        </Row>

                        <Row>

                            <Col span="12">
                                <Row>
                                    <Col span="13">
                                        <FormItem label="管理员地址" prop="channelAdminAddressValue">
                                            <Cascader :load-data="locationChange" :data="location" v-model="basicTypeForm.channelAdminAddressValue" placeholder="下拉选择省市"  class="show_cascader_input" :clearable="false">
                                            </Cascader>
                                        </FormItem>
                                    </Col>

                                    <Col span="10" offset="1">
                                        <FormItem prop="channelAdminAddressDetail" class="addressDetail">
                                            <Input v-model.trim="basicTypeForm.channelAdminAddressDetail" placeholder="请输入详细地址" maxlength="50" style="vertical-align: top;" class="detail_cascader_input"/>
                                        </FormItem>
                                    </Col>
                                </Row>
                            </Col>
                            <Col span="12">
                                <FormItem label="公司人数" prop="companiesNumber">
                                    <InputNumber :max="1000" :min="0" v-model="basicTypeForm.companiesNumber" class="w200" ></InputNumber>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row>

                            <Col span="12">
                                <Row>
                                    <Col span="13">
                                        <FormItem label="注册地址" prop="channelAddressValue">
                                            <Cascader :load-data="locationChange" :data="location" v-model="basicTypeForm.channelAddressValue" placeholder="下拉选择省市"  class="show_cascader_input" :clearable="false">
                                            </Cascader>
                                        </FormItem>
                                    </Col>

                                    <Col span="10" offset="1">
                                        <FormItem prop="channelAddressDetail" class="addressDetail">
                                            <Input v-model.trim="basicTypeForm.channelAddressDetail" placeholder="请输入详细地址" maxlength="50" style="vertical-align: top;" class="detail_cascader_input"/>
                                        </FormItem>
                                    </Col>
                                </Row>
                            </Col>
                        </Row>

                        <Row>
                            <Col span="12">
                                <Row>
                                    <Col span="13">
                                        <FormItem label="办公地址" prop="officeAddressValue">
                                            <Cascader :load-data="locationChange" :data="location"    v-model="basicTypeForm.officeAddressValue" placeholder="下拉选择省市"  class="show_cascader_input" :clearable="false">
                                            </Cascader>
                                        </FormItem>
                                    </Col>
                                    <Col span="10" offset="1">
                                        <FormItem prop="officeAddressDetail" class="addressDetail">
                                            <Input v-model.trim="basicTypeForm.officeAddressDetail"  placeholder="请输入详细地址" maxlength="50" style="vertical-align: top;" class="detail_cascader_input"/>
                                        </FormItem>
                                    </Col>
                                </Row>
                            </Col>

                        </Row>
                        <Row>
                            <Col span="8">
                                <FormItem label="地址经度" prop="longitude">
                                    <Input v-model.trim="basicTypeForm.longitude"    class="w200"  placeholder="取办公地址"/>
                                </FormItem>
                            </Col>
                            <Col span="8">
                                <FormItem label="地址纬度" prop="latitude">
                                    <Input v-model.trim="basicTypeForm.latitude"    class="w200"  placeholder="取办公地址"/>
                                </FormItem>
                            </Col>

                            <Col span="8">
                                <FormItem label="经纬度范围（km）" prop="longitudeLatitudeRange">
                                    <Input v-model.trim="basicTypeForm.longitudeLatitudeRange"    class="w200"  placeholder="请输入"/>
                                </FormItem>
                            </Col>
                        </Row>

                        <Row>
                            <Col span="8">
                                <FormItem label="经营场所面积" prop="businessArea">
                                    <Input v-model.trim="basicTypeForm.businessArea"    class="w200"  placeholder="请输入"/>
                                </FormItem>
                            </Col>

                            <Col span="8">
                                <FormItem label="汇款对象" prop="paymentObject">
                                    <RadioGroup v-model="basicTypeForm.paymentObject"     >
                                        <Radio :false-value="''"  :key="radio.id" :label="radio.value" :true-value="radio.value" v-bind:disabled="paymentObjectDisabled" v-for="(radio) in paymentObjectList">{{radio.title}} </Radio>
                                    </RadioGroup>
                                </FormItem>
                            </Col>

                            <Col span="8">
                                <FormItem label="注册日期" prop="registrationDate" >
                                    <Date-picker type="date" v-model="basicTypeForm.registrationDate"    class="w200"  placeholder="选择日期" ></Date-picker>
                                </FormItem>
                            </Col>

                        </Row>

                        <Row>
                            <Col span="8">
                                <FormItem label="注册资金(单位：万元)" prop="registeredCapital">
                                    <Input v-model.trim="basicTypeForm.registeredCapital"    class="w200"  placeholder="请输入"/>
                                </FormItem>
                            </Col>

                            <Col span="8">
                                <FormItem label="实收资本(单位：万元)" prop="subscribedCapital">
                                    <Input v-model.trim="basicTypeForm.subscribedCapital"   class="w200"  placeholder="请输入"/>
                                </FormItem>
                            </Col>
                            <Col span="8">
                                <FormItem label="主营品牌" prop="mainBrand">
                                    <div style="height:200px;overflow-y:auto">
                                        <Tree :data="baseData"  ref="baseTree" show-checkbox v-model="basicTypeForm.mainBrand"   multiple> </Tree>
                                    </div>
                                </FormItem>
                            </Col>
                        </Row>
                    </div>
                </div>
                </Card>

            </Form>
        </div>


    </div>
</template>

<script>
    import PlaceCascade from "@/components/place-cascade"
    import vueEvent from "_p/afs-apply/assets/js/vueEvent.js"
    import {
        //根据渠道代码查询渠道信息
        getChannelBasicInfoById,
        //新增渠道保存
        addChannel,
        //暂存
        addStagingChannel,
        //多条件查询渠道基本信息
        getChannelListData,
        //获取渠道风控信息
        getChannelRiskInfoById,
        //获取渠道保证金信息
        getChannelQuotaInfoById,
        //保存黑名单
        saveBlack,
        //验证黑名单
        blackCleack,
        //查询授权区域信息
        getMainAreaById,
        //查询主营品牌信息
        getCarBrandById,
        //提交审批
        channelSubmit,
        //授权车型
        getVehicleById,
        //获取渠道展业区域
        getAreaListData,
        //统一社会信用代码重复验证
        socUniCrtCodeCheck,
        //提交审批(工作流)
        channelSubmitWorkflow,
    } from  "@/projects/afs-channel/api/dealer/dealer";

    import utils from "@/libs/util.js";
    import {
        getDictDataByType
    } from "_p/basic/api/admin/datadic.js";

    import {
        getAllAddressList,
        getBrandTree,
        getLocation,
        //区域经理查询
        getAllRegionalManager
    } from "_p/afs-channel/api/common/common.js"

    import MapModal from '_p/afs-channel/pages/common/map/MapModal';

    import {deepClone} from "@/libs/utils/ObjectClone";
    export default {
        name:"basic_info",
        data(){

            return{
                //注音品牌查询
                searchKey:"",
                //注音品牌查询全局变量
                mainCarSearch:[],
                //新车授权区域查询
                searchAreasDataKey:"",
                areasDataSearch:[],
                //二手车授权区域查询
                searchAreasDataOldKey:"",
                areasDataOldSearch:[],
                //新车授权车型查询
                searchCarsDataKey:"",
                carsDataSearch:[],
                //二手车授权车新查询
                searchMainCarOldKey:"",
                carsDataOldSearch:[],



                loading:false,
                submitLoading: false,
                showGroupNewCar:"",
                showGroupOldCar:"",
                paymentObjectDisabled:false,
                //禁用新车复选框
                businessTypeDisabled:"0",
                //禁用二手车复选框
                businessTypeOldDisabled:"0",
                //禁用新车表单
                businessTypeNewInfo:"0",
                //禁用二手车表单
                businessTypeOldInfo:"0",
                //优质等级Title
                qualityGradeTitle:"",
                //二手车优质等级Title
                qualityGradeOldTitle:"",
                //是否禁用新车按钮：默认否
                //viewNewCar:"1",
                //是否禁用二手车按钮：默认否
                //viewOldCar:"1",
                disabledPaymentObject:"0",
                readOnly:false,
                isShowModel:false,
                expandLevel: 0,
                carLevel: 0,
                //黑名单
                modalTitle: "",
                //展业区域
                areaTitle:"",
                //黑明单申请弹窗
                blackApplyVisible: false,
                //展业区域弹窗
                areaVisible:false,
                typeCode:"1",
                mainCar:[],
                mainArea:[],
                //渠道归属数据字典
                channelBelongList:[],
                //汇款对象
                paymentObjectList:[],
                location:[],
                //业务类型字典
                businessTypeList:[],

                //优质等级字典处理
                qualityGradeList:[],

                //渠道评级
                channelGradeList:[],
                //区域经理
                regionalManager:[],

                searchForm: {
                    pageNumber: 1,
                    pageSize: 10,
                    areaId:[],
                },
                dataArea: [],
                totalArea: 0,
                basicTypeForm:{
                    //admin地址省市区
                    channelAdminAddressValue:[],
                    //注册地址省市区
                    channelAddressValue:[],
                    //办公地址省市区
                    officeAddressValue:[],
                    newCarRole:"",
                    oldCarRole:"",
                    pageNumber: 1,
                    pageSize: 10,
                    //渠道名称
                    channelFullName:"",
                    //上线日期
                    onlineDate:"",
                    //统一社会信用代码
                    socUniCrtCode:"",
                    //法人
                    legalPerson:"",
                    //法人身份证号
                    legalPersonIdCard:"",
                    //法人电话
                    legalPersonTel:"",
                    //实际控制人
                    actualController:"",
                    //实际控制人电话
                    actualControllerTel:"",
                    //实际控制人身份证号
                    actualControllerIdCard:"",
                    //管理员姓名
                    channelAdmin:"",
                    //管理员电话
                    channelAdminTel:"",
                    //管理员证件号码
                    channelAdminIdCard:"",
                    //管理员邮箱
                    channelAdminMail:"",
                    channelAdminAddressDetail:"",
                    channelAddressDetail:"",
                    officeAddressDetail:"",
                    //地址经纬度
                    longitude:"",
                    latitude:"",
                    //经纬度范围（km）
                    longitudeLatitudeRange:"",
                    //公司人数
                    companiesNumber:1,
                    //经营场所面积
                    businessArea:"",
                    //汇款对象
                    paymentObject:"",
                    //注册日期
                    registrationDate:"",
                    //注册资金(单位：万元)
                    registeredCapital:"",
                    //实收资本(单位：万元)
                    subscribedCapital:"",
                    //业务类型
                    businessType:[],
                    //资产净值
                    netAssetValue:"",
                    //经营年限
                    businessLife:"",
                    //Gps厂商授权
                    gpsVendorAuthor:[],
                    //资产负债率
                    assetLiabilityRatio:"",
                    //上一年度经营利润
                    operatingProfit:"",
                    //Gps安装方式
                    gpsInstalMode:[],
                    //业绩
                    achievement:"",
                    //利润率增长率
                    proGrowthRate:"",
                    //销售收入增长率
                    saleIncreaseRate:"",
                    //流动比例
                    currentRatio:"",
                    //优质等级
                    qualityGrade:"",
                    //二手车优质等级
                    qualityGradeOld:"",
                    //有效期
                    validDate:[],
                    //二手车有效期
                    validDateOld:[],
                    //车辆类型
                    carType:[],
                    //二手车车辆类型
                    carTypeOld:[],
                    //区域经理
                    customerManager:"",
                    //二手车区域经理
                    customerManagerOld:"",
                    //二手车账号最大数量
                    accountMaxNumOld:1,
                    //新车账号最大数量
                    accountMaxNum:1,
                    //层级最大数量
                    hierarchy:1,
                    //评级
                    channelGrade:"",
                    //二手车评级
                    channelGradeOld:"",
                    //保证金
                    channelDeposit:"",
                    //二手车保证金
                    channelDepositOld:"",
                    //是否控制额度
                    isLimitPut:"",
                    //二手车是否控制额度
                    isLimitPutOld:"",
                    //是否控制额度
                    isLimitPledge:"",
                    //二手车是否控制额度
                    isLimitPledgeOld:"",
                    //签放额度
                    limitPut:"",
                    //签放额度
                    limitPutOld:"",
                    //先放后抵额度
                    limitPledge:"",
                    //二手车先放后抵额度
                    limitPledgeOld:"",
                    //签放额度临时额度
                    temporaryLimitPut:"",
                    //二手车签放额度临时额度
                    temporaryLimitPutOld:"",
                    //先放后抵额度临时额度
                    temporaryLimitPledge:"",
                    //二手车先放后抵额度临时额度
                    temporaryLimitPledgeOld:"",
                    //签放额度有效期
                    limitPutTime:"",
                    //二手车签放额度有效期
                    limitPutTimeOld:"",
                    //先放后抵额度有效期
                    limitPledgeTime:"",
                    //二手车先放后抵额度有效期
                    limitPledgeTimeOld:"",
                    //签放额度占用
                    limitPutTake:"",
                    //二手车签放额度占用
                    limitPutTakeOld:"",
                    //先放后抵额度占用
                    limitPledgeTake:"",
                    //二手车先放后抵额度占用
                    limitPledgeTakeOld:"",
                    //剩余签放额度
                    limitPutResidue:"",
                    //二手车剩余签放额度
                    limitPutResidueOld:"",
                    //剩余先放后抵额度
                    limitPledgeResidue:"",
                    //二手车剩余先放后抵额度
                    limitPledgeResidueOld:"",
                    //区域是否生效
                    authRegionSwitch:"",
                    //二手车区域是否生效
                    authRegionSwitchOld:"",
                    //车型是否生效
                    authVehicleTypeSwitch:"",
                    //二手车是否生效
                    authVehicleTypeSwitchOld:"",
                    //经纬度是否控制
                    longitudeLatitudeSwitch:"",
                    //业务人员关联车商
                    personRelCardealerSwitch:"",
                    //进件选择车商
                    choiceCardealerSwitch:"",
                },
                baseData: [],
                areasData:[],
                carsData: [],
                carsDataOld:[],
                areasDataOld:[],
                showGroupNewCar:"0",//默认隐藏新车
                showGroupOldCar:"0",//默认隐藏二手车
                mapModal: false, // 地图弹窗
                mapLocation:'', // 地图定位
                mapAddress:'', // 详细地址
                canOpenMapModal: false, // 是否可以打开地图弹窗
            }
        },
        components:{
            PlaceCascade,
            MapModal
        },
        props:{
            channelType:{
                type:String,
            },

            newCarRole:{
                type:String,
            },
            oldCarRole:{
                type:String,
            },
            channelStatus:{
                type:String,
            },
            channelStatusOldCar:{
                type:String,
            }
        },
        watch:{

        },
        methods:{
            init() {
            },

            getChannelInfo(v) {
                //根据id查询渠道基本信息
                this.loading = true;
                getChannelBasicInfoById(v).then(res => {
                    this.loading = false;
                    if (res.code === "0000") {
                        this.basicTypeForm.id=res.data[0].id;
                        this.basicTypeForm.channelCode=res.data[0].channelCode;
                        this.basicTypeForm.channelFullName=res.data[0].channelFullName;
                        this.basicTypeForm.onlineDate=res.data[0].onlineDate;
                        this.basicTypeForm.socUniCrtCode=res.data[0].socUniCrtCode;
                        this.basicTypeForm.legalPerson=res.data[0].legalPerson;
                        this.basicTypeForm.legalPersonIdCard=res.data[0].legalPersonIdCard;
                        this.basicTypeForm.legalPersonTel=res.data[0].legalPersonTel;
                        this.basicTypeForm.actualController=res.data[0].actualController;
                        this.basicTypeForm.actualControllerTel=res.data[0].actualControllerTel;
                        this.basicTypeForm.actualControllerIdCard=res.data[0].actualControllerIdCard;
                        this.basicTypeForm.channelAdmin=res.data[0].channelAdmin;
                        this.basicTypeForm.channelAdminTel=res.data[0].channelAdminTel;
                        this.basicTypeForm.channelAdminMail=res.data[0].channelAdminMail;
                        //this.basicTypeForm.longitudeLatitude=res.data[0].longitudeLatitude;
                        this.basicTypeForm.longitude=res.data[0].longitude;
                        this.basicTypeForm.latitude=res.data[0].latitude;
                        this.basicTypeForm.longitudeLatitudeRange=res.data[0].longitudeLatitudeRange;
                        this.basicTypeForm.businessArea=res.data[0].businessArea;
                        this.basicTypeForm.paymentObject=res.data[0].paymentObject;
                        this.basicTypeForm.registrationDate=res.data[0].registrationDate;
                        this.basicTypeForm.channelBelong=res.data[0].channelBelong;
                        this.basicTypeForm.hierarchy=res.data[0].hierarchy;
                        this.basicTypeForm.companiesNumber=res.data[0].companiesNumber;
                        this.basicTypeForm.channelAdminIdCard =res.data[0].channelAdminIdCard;
                        if(res.data[0].registeredCapital){
                            this.basicTypeForm.registeredCapital=res.data[0].registeredCapital+"";
                        }
                        if(res.data[0].assetLiabilityRatio){
                            this.basicTypeForm.assetLiabilityRatio=res.data[0].assetLiabilityRatio+"";
                        }
                        if(res.data[0].businessLife){
                            this.basicTypeForm.businessLife=res.data[0].businessLife+"";
                        }
                        if(res.data[0].operatingProfit){
                            this.basicTypeForm.operatingProfit=res.data[0].operatingProfit+"";
                        }
                        if(res.data[0].achievement){
                            this.basicTypeForm.achievement=res.data[0].achievement+"";
                        }
                        if(res.data[0].subscribedCapital){
                            this.basicTypeForm.subscribedCapital=res.data[0].subscribedCapital+"";
                        }
                        if(res.data[0].netAssetValue){
                            this.basicTypeForm.netAssetValue=res.data[0].netAssetValue+"";
                        }
                        if(res.data[0].proGrowthRate){
                            this.basicTypeForm.proGrowthRate=res.data[0].proGrowthRate+"";
                        }
                        if(res.data[0].saleIncreaseRate){
                            this.basicTypeForm.saleIncreaseRate=res.data[0].saleIncreaseRate+"";
                        }
                        if(res.data[0].currentRatio){
                            this.basicTypeForm.currentRatio=res.data[0].currentRatio+"";
                        }
                        this.basicTypeForm.longitudeLatitudeSwitch=res.data[0].longitudeLatitudeSwitch;
                        this.basicTypeForm.personRelCardealerSwitch=res.data[0].personRelCardealerSwitch;
                        this.basicTypeForm.choiceCardealerSwitch=res.data[0].choiceCardealerSwitch;
                        this.basicTypeForm.businessType=res.data[0].businessType.split(',');
                        this.basicTypeForm.gpsVendorAuthor=res.data[0].gpsVendorAuthor.split(',');
                        this.basicTypeForm.gpsInstalMode=res.data[0].gpsInstalMode.split(',');

                        let channelAdminAddressValue = [];
                        channelAdminAddressValue[0]=res.data[0].channelAdminProvince;
                        channelAdminAddressValue[1]=res.data[0].channelAdminCity;
                        this.basicTypeForm.channelAdminAddressValue=channelAdminAddressValue;
                        this.basicTypeForm.channelAdminAddressDetail=res.data[0].channelAdminAddress;

                        let channelAddressValue = [];
                        channelAddressValue[0]=res.data[0].channelProvince;
                        channelAddressValue[1]=res.data[0].channelCity;
                        this.basicTypeForm.channelAddressValue=channelAddressValue;
                        this.basicTypeForm.channelAddressDetail=res.data[0].channelAddress;

                        let officeAddressValue = [];
                        officeAddressValue[0]=res.data[0].officeProvince;
                        officeAddressValue[1]=res.data[0].officeCity;
                        this.basicTypeForm.officeAddressValue=officeAddressValue;
                        this.basicTypeForm.officeAddressDetail=res.data[0].officeAddress;

                        let channelInfo = this.basicTypeForm;
                      /*  this.$emit('passmsg',channelInfo)
                        this.carRole();*/
                    }
                });




            },

            //地址公共信息调用
            locationChange(item, callback) {
                item.loading = true;
                getLocation({upperCode: item.value}).then(res => {
                    if (res.code === "0000") {
                        res.data.forEach(function (item) {
                            if (item.isParent) {
                                item.loading = false;
                                item.children = [];
                            }
                        });
                        item.children = res.data;
                        item.loading = false;
                        callback();
                    }
                })
            },


            getLocationData() {
                let param = ""
                param = {
                    level: '1',
                    upperCode: '1'
                };
                getLocation(param).then((res) => {
                    if (res.code == "0000") {
                        res.data.forEach(item => {
                            // 表明是否是父节点
                            if (item.isParent) {
                                item.loading = false;
                                item.children = [];
                            }
                        })
                    }
                    this.location.push(...res.data);
                })
            },



            //主营品牌
            getBaseTreeList(v){
                let param = {
                    type:[],
                }
                getBrandTree(param).then(res => {
                    this.loading = false;
                    if (res.code === "0000") {
                        // 仅展开指定级数 默认一级
                        let expandLevel = this.carLevel;
                        res.data.forEach(function (e) {
                            if (expandLevel == "0") {
                                if (e.carLevel === "0") {
                                    e.expand = true;
                                }
                                if (e.children && e.children.length > 0) {
                                    e.children.forEach(function (c) {
                                        if (c.carLevel === "1") {
                                            c.expand = false;
                                        }
                                    });
                                }
                            } else {
                                if (e.children && e.children.length > 0) {
                                    e.children.forEach(function (c) {
                                        if (expandLevel == 0) {
                                            if (c.carLevel === "1") {
                                                c.expand = false;
                                            }
                                        }
                                    });
                                }
                            }
                        });
                        let mainCarSearchTemp = deepClone(res.data);
                        this.mainCarSearch=deepClone(res.data);
                        if(v!=null && v!="" && v!= undefined){
                            //根据渠道id查询主营品牌
                            getCarBrandById(v).then(resMainCar => {
                                this.loading = false;
                                if (resMainCar.code === "0000") {
                                    let cars = resMainCar.data;
                                    this.checkMainCarTree(mainCarSearchTemp, cars);
                                    this.baseData=mainCarSearchTemp;
                                }
                            })
                        }else{
                            this.baseData= deepClone(res.data);
                        }
                    }
                });
            },

            // 递归判断子节点
            checkMainCarTree(mainCarData, cars) {
                let that = this;
                mainCarData.forEach(function (p) {
                    if (that.hasMainCar(p, cars)=="0") {
                        //层级表示第一层级，第二层级不用勾选
                        p.checked = false;
                    }else if(that.hasMainCar(p, cars)=="1") {
                        p.checked = true;
                    }else if(that.hasMainCar(p, cars)=="2"){
                        if(p.carLevel=="0"){
                            p.checked = false;
                        }else{
                            p.checked = true;
                        }
                    }else{
                        if(p.carLevel=="0" || p.carLevel=="1" ){
                            p.checked = false;
                        }else{
                            p.checked = true;
                        }
                    }
                    if (p.children && p.children.length > 0) {
                        that.checkMainCarTree(p.children, cars);
                    }
                });
            },

            //判断主营品牌节点勾选
            hasMainCar(p, cars) {
                //flag 等于 0 表示code相等
                let flag = "0";
                for (let i = 0; i < cars.length; i++) {
                    if (p.code === cars[i].code && cars[i].code=="00" &&  cars[i].indeterminate=="false") {
                        //表示一级品牌名称非半选状态：即为全选状态，数据库只有一笔数据
                        flag="1";
                        if(cars[i].indeterminate=="false"){
                            p.indeterminate=false;
                        }else{
                            p.indeterminate=true;
                        }
                        break;
                    }else if (p.code === cars[i].code &&  cars[i].indeterminate=="false") {
                        //表示二级品牌非半选状态：即为全选状态，数据库只有一笔数据
                        flag = "2";
                        if(cars[i].indeterminate=="false"){
                            p.indeterminate=false;
                        }else{
                            p.indeterminate=true;
                        }
                        break;
                    }else if (p.code === cars[i].code){
                        //表示三级品牌非半选状态：即为全选状态，数据库只有一笔数据
                        flag = "3";
                        p.indeterminate=true;
                        break;
                    }
                }
                return flag;
            },


            getMainAreaListNew(v){
                getAllAddressList().then(res => {
                    this.loading = false;
                    let _this = this;
                    if (res.code === "0000") {
                        // 仅展开指定级数 默认一级
                        let expandLevel = this.expandLevel;
                        res.data.forEach(function (e) {
                            if (expandLevel == "0") {
                                if (e.addrLevel === "0") {
                                    e.expand = true;
                                    //新车状态
                                    if(_this.channelStatus=="00"){
                                        e.disabled=true;
                                    }
                                }
                                if (e.children && e.children.length > 0) {
                                    e.children.forEach(function (c) {
                                        if (c.addrLevel === "1") {
                                            c.expand = false;
                                            //新车状态
                                            if(_this.channelStatus=="00"){
                                                c.disabled=true;
                                            }
                                        }
                                    });
                                }
                            } else {
                                if (e.children && e.children.length > 0) {
                                    e.children.forEach(function (c) {
                                        if (expandLevel == 1) {
                                            if (c.addrLevel === "1") {
                                                c.expand = false;
                                                //新车状态
                                                if(_this.channelStatus=="00"){
                                                    c.disabled=true;
                                                }
                                            }
                                        }
                                    });
                                }
                            }
                        });
                        //this.areasData= deepClone(res.data);
                        this.areasDataSearch=deepClone(res.data);
                        if(v!=null && v!="" && v!= undefined){
                            //根据渠道id查询授权区域
                            getMainAreaById(v).then(resMainArea => {
                                this.loading = false;
                                if (resMainArea.code === "0000") {
                                    let areas = resMainArea.data;
                                    if(areas.length>0){
                                        areas.forEach((item, i) => {
                                            if(item.businessType=="01"){
                                                //新车
                                                this.checkAreaTree(this.areasDataSearch, areas,"01");
                                            }
                                        })
                                    }else{
                                        this.areasData= deepClone(res.data)
                                    }
                                }
                            })
                        }else{
                            this.areasData= deepClone(res.data)
                        }
                    }
                });
            },

            getMainAreaListOld(v){
                getAllAddressList().then(res => {
                    this.loading = false;
                    let _this = this;
                    if (res.code === "0000") {
                        // 仅展开指定级数 默认一级
                        let expandLevel = this.expandLevel;
                        res.data.forEach(function (e) {
                            if (expandLevel == "0") {
                                if (e.addrLevel === "0") {
                                    e.expand = true;
                                    //新车状态
                                    if(_this.channelStatusOldCar=="00"){
                                        e.disabled=true;
                                    }
                                }
                                if (e.children && e.children.length > 0) {
                                    e.children.forEach(function (c) {
                                        if (c.addrLevel === "1") {
                                            c.expand = false;
                                            //新车状态
                                            if(_this.channelStatusOldCar=="00"){
                                                c.disabled=true;
                                            }
                                        }
                                    });
                                }
                            } else {
                                if (e.children && e.children.length > 0) {
                                    e.children.forEach(function (c) {
                                        if (expandLevel == 1) {
                                            if (c.addrLevel === "1") {
                                                c.expand = false;
                                                //新车状态
                                                if(_this.channelStatusOldCar=="00"){
                                                    c.disabled=true;
                                                }
                                            }
                                        }
                                    });
                                }
                            }
                        });
                        //this.areasDataOld =res.data;
                        this.areasDataOldSearch=deepClone(res.data);
                        if(v!=null && v!="" && v!= undefined){
                            //根据渠道id查询授权区域
                            getMainAreaById(v).then(resMainArea => {
                                this.loading = false;
                                if (resMainArea.code === "0000") {
                                    let areas = resMainArea.data;
                                    console.log(areas,"444444444444444");
                                    if(areas.length>0){
                                        console.log(this.areasDataOld,"555555555555");
                                        areas.forEach((item, i) => {
                                            if(item.businessType=="02"){
                                                this.checkAreaTree(this.areasDataOldSearch, areas,"02");
                                            }
                                        })
                                    }else{
                                        console.log(this.areasDataOld,"1221321312321312");
                                        this.areasDataOld= deepClone(res.data)
                                    }
                                }
                            })
                        }else{
                            this.areasDataOld= deepClone(res.data)
                        }
                    }
                });
            },
            // 递归判断子节点
            checkAreaTree(areasData, areas,type) {
                let that = this;
                areasData.forEach(function (p) {
                    if (that.hasArea(p, areas,type)) {
                        if(p.addrLevel==0||p.addrLevel==1){
                            //层级表示第一层级，第二层级不用勾选
                            p.checked = false;
                        }else{
                            p.checked = true;
                        }
                    } else {
                        p.checked = false;
                    }
                    if (p.children && p.children.length > 0) {
                        that.checkAreaTree(p.children, areas,type);
                    }
                });
                if(type=="01"){
                    //新车
                    this.areasData = deepClone(this.areasDataSearch);
                }
                if(type=="02"){
                    //二手车
                    this.areasDataOld = deepClone(this.areasDataOldSearch);
                }
            },

            // 判断渠道授权区域节点勾选
            hasArea(p, areas,type) {
                let flag = false;
                for (let i = 0; i < areas.length; i++) {
                    if ((p.value === areas[i].code)&&areas[i].businessType==type) {
                        flag = true;
                        break;
                    }
                }
                if (flag) {
                    return true;
                }
                return false;
            },

            //授权车型
            getCarsTreeList(){
                let param = {
                    type:this.basicTypeForm.carType,
                };
                if(param.type==""){
                    param.type=[];
                }
                getBrandTree(param).then(res => {
                    this.loading = false;
                    if (res.code === "0000") {
                        // 仅展开指定级数 默认一级
                        let expandLevel = this.carLevel;
                        res.data.forEach(function (e) {
                            if (expandLevel == "0") {
                                if (e.carLevel === "0") {
                                    e.expand = true;
                                }
                                if (e.children && e.children.length > 0) {
                                    e.children.forEach(function (c) {
                                        if (c.carLevel === "0") {
                                            c.expand = false;
                                        }
                                    });
                                }
                            } else {
                                if (e.children && e.children.length > 0) {
                                    e.children.forEach(function (c) {
                                        if (expandLevel == 0) {
                                            if (c.carLevel === "1") {
                                                c.expand = false;
                                            }
                                        }
                                    });
                                }
                            }
                        });
                        this.carsData= deepClone(res.data);
                        this.carsDataOld = deepClone(res.data);
                        this.carsDataSearch= deepClone(res.data);
                        this.carsDataOldSearch = deepClone(res.data);
                    }
                });
            },
            // 递归判断子节点
            checkCarsTree(carsData, cars,type) {
                let that = this;
                carsData.forEach(function (p) {
                    if (that.hasCars(p, cars,type)) {
                        if(p.carLevel=='0'||p.carLevel=='1'){
                            //层级表示第一层级，第二层级不用勾选
                            p.checked = false;
                        }else{
                            p.checked = true;
                        }
                    } else {
                        p.checked = false;
                    }
                    if (p.children && p.children.length > 0) {
                        that.checkCarsTree(p.children, cars,type);
                    }
                });
            },
            //判断授权车型节点勾选
            hasCars(p, cars,type) {
                let flag = "0";
                for (let i = 0; i < cars.length; i++) {

                    if (p.code === cars[i].code && cars[i].code=="00" &&  cars[i].indeterminate=="false" && cars[i].businessType===type ) {
                        //表示一级品牌名称非半选状态：即为全选状态，数据库只有一笔数据
                        flag="1";
                        if(cars[i].indeterminate=="false"){
                            p.indeterminate=false;
                        }else{
                            p.indeterminate=true;
                        }
                        break;
                    }else if (p.code === cars[i].code &&  cars[i].indeterminate=="false" && cars[i].businessType===type) {
                        //表示二级品牌非半选状态：即为全选状态，数据库只有一笔数据
                        flag = "2";
                        if(cars[i].indeterminate=="false"){
                            p.indeterminate=false;
                        }else{
                            p.indeterminate=true;
                        }
                        break;
                    }else if (p.code === cars[i].code && cars[i].businessType===type){
                        //表示三级品牌非半选状态：即为全选状态，数据库只有一笔数据
                        flag = "3";
                        p.indeterminate=true;
                        break;
                    }
                }

                return flag;
            },
            checkAllNewCar(v){
                let param = {
                    type:this.basicTypeForm.carType,
                }
                if(param.type==""){
                    console.log(param.type,"新车类型");
                    param.type=[];
                }
                let _this = this;
                getBrandTree(param).then(res => {
                    this.loading = false;
                    if (res.code === "0000") {
                        // 仅展开指定级数 默认一级
                        let expandLevel = this.carLevel;
                        res.data.forEach(function (e) {
                            if (expandLevel == "0") {
                                if (e.carLevel === "0") {
                                    e.expand = true;
                                    if(_this.channelStatus=="00"){
                                        e.disabled=true;
                                    }
                                }
                                if (e.children && e.children.length > 0) {
                                    e.children.forEach(function (c) {
                                        if (c.carLevel === "1") {
                                            c.expand = false;
                                            if(_this.channelStatus=="00"){
                                                c.disabled=true;
                                            }
                                        }
                                    });
                                }
                            } else {
                                if (e.children && e.children.length > 0) {
                                    e.children.forEach(function (c) {
                                        if (expandLevel == 0) {
                                            if (c.carLevel === "1") {
                                                c.expand = false;
                                                if(_this.channelStatus=="00"){
                                                    c.disabled=true;
                                                }
                                            }
                                        }
                                    });
                                }
                            }
                        });
                        let carsDataSearchTemp = deepClone(res.data);
                        this.carsDataSearch= deepClone(res.data);
                        if(v!=null && v!="" && v!= undefined){
                            //根据渠道id查询授权车型
                            getVehicleById(v).then(resCars => {
                                this.loading = false;
                                if (resCars.code === "0000") {
                                    let cars = resCars.data;
                                    if(cars.length>0){
                                        cars.forEach((item, i) => {
                                            if(item.businessType=="01"){
                                                //新车
                                                this.checkCarsTree(carsDataSearchTemp, cars,"01");
                                            }
                                        })
                                        this.carsData= carsDataSearchTemp;
                                    }else{
                                        this.carsData= res.data;
                                    }
                                }
                            })
                        }else{
                            this.carsData= res.data;
                        }
                    }
                });
            },

            checkAllOldCar(v){
                let param = {
                    type:this.basicTypeForm.carTypeOld,
                }
                let _this = this;
                console.log(param.type,"二手车类型----------");
                if(param.type==""){
                    console.log(param.type,"二手车类型");
                    param.type=[];
                }
                getBrandTree(param).then(res => {
                    this.loading = false;
                    if (res.code === "0000") {
                        // 仅展开指定级数 默认一级
                        let expandLevel = this.carLevel;
                        res.data.forEach(function (e) {
                            if (expandLevel == "0") {
                                if (e.carLevel === "0") {
                                    e.expand = true;
                                    //新车状态
                                    if(_this.channelStatusOldCar=="00"){
                                        e.disabled=true;
                                    }
                                }
                                if (e.children && e.children.length > 0) {
                                    e.children.forEach(function (c) {
                                        if (c.carLevel === "1") {
                                            c.expand = false;
                                            if(_this.channelStatusOldCar=="00"){
                                                c.disabled=true;
                                            }
                                        }
                                    });
                                }
                            } else {
                                if (e.children && e.children.length > 0) {
                                    e.children.forEach(function (c) {
                                        if (expandLevel == 0) {
                                            if (c.carLevel === "1") {
                                                c.expand = false;
                                                if(_this.channelStatusOldCar=="00"){
                                                    c.disabled=true;
                                                }
                                            }
                                        }
                                    });
                                }
                            }
                        });
                        //this.carsDataOld= res.data;
                        let carsDataOldSearchTemp = deepClone(res.data);
                        this.carsDataOldSearch= deepClone(res.data);
                        if(v!=null && v!="" && v!= undefined){
                            //根据渠道id查询授权车型
                            getVehicleById(v).then(resCars => {
                                this.loading = false;
                                if (resCars.code === "0000") {
                                    let cars = resCars.data;
                                    if(cars.length>0){
                                        cars.forEach((item, i) => {
                                            if(item.businessType=="02"){
                                                //二手车
                                                this.checkCarsTree(carsDataOldSearchTemp, cars,"02");
                                            }
                                        })
                                        this.carsDataOld=carsDataOldSearchTemp;
                                    }else{
                                        this.carsDataOld= res.data;
                                    }
                                }
                            })
                        }else{
                            this.carsDataOld= res.data;
                        }
                    }
                });
            },

            // 查询数据字典
            initDataDic() {
                this.channelBelongType();
                this.paymentObjectType();
                this.qualityGradeType();
            },
            //渠道归属数据字典
            channelBelongType() {
                let param = {
                    type: "channelBelong"
                }
                getDictDataByType(param.type).then(res => {
                    if (res.code === "0000") {
                        this.channelBelongList = res.data;
                    }
                });
            },
            //汇款对象数据字典
            paymentObjectType() {
                let param = {
                    type: "paymentObject"
                }
                getDictDataByType(param.type).then(res => {
                    if (res.code === "0000") {
                        this.paymentObjectList = res.data;
                    }
                });
            },
            //优质等级
            qualityGradeType() {
                let param = {
                    type: "qualityGrade"
                }
                getDictDataByType(param.type).then(res => {
                    if (res.code === "0000") {
                        this.qualityGradeList = res.data;
                    }
                });
            },


        },
        created() {
            this.initDataDic();
        },
        mounted() {
            this.getLocationData();
            this.init();
        },
    }
</script>

<style>
    .basis-info .ivu-icon-ios-search:before{
        font-size: 18px;
        position: absolute;
        right: 5px;
    }
    .basis-info .ivu-input[disabled]{
        color: black;
    }
    .basis-info span.ivu-select-selected-value{
        color: black;
    }
    .basis-info .ivu-input-number-input[disabled]{
        color:black;
    }
    .addressDetail .ivu-form-item-content{
        margin-left: 0 !important;
    }

</style>
